#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include "global_header.h"




QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void drawControlpoints(std::vector<std::vector<double>> controlPoints);

    //void drawBezier(std::vector<std::vector<double>> controlPoints);
    void loadSTLFile();

    std::vector<double> computeRiemannianCentroid(vtkSmartPointer<vtkPolyData> polyData);


    std::vector<double> PointOntoSurface(
        std::vector<double> point,
        vtkSmartPointer<vtkPolyData> polyData);

    void drawBezier(
        vtkPolyData* mesh,
        const std::vector<std::vector<double>>& controlPoints
        );

    std::vector<double> GeodesicInterpolation(
        vtkPolyData* mesh,
        const std::vector<double>& startPoint,
        const std::vector<double>& endPoint,
        double t);


    static void OnLeftButtonClick(
        vtkObject* caller,
        unsigned long eid,
        void* clientdata,
        void* calldata);
    static void OnRightButtonClick(
        vtkObject* caller,
        unsigned long eid,
        void* clientdata,
        void* calldata);






    // vtkSmartPointer<vtkPolyData> GetCachedGeodesicPath(const std::vector<double>& p1, const std::vector<double>& p2);
    vtkSmartPointer<vtkPolyData> path;




private slots:


    void on_pushButton_addPointpushButton_addPoint_clicked();

    void on_pushButton_drawBezier_clicked();

    void on_pushButton_loadfile_clicked();


    void on_pushButton_translucent_clicked();

    void on_pushButton_deleteControlpoints_clicked();

    void on_pushButton_resetSTLmodel_clicked();

private:
    Ui::MainWindow *ui;
    vtkSmartPointer<vtkRenderer> renderer;
    vtkSmartPointer<vtkRenderWindow> renderWindow;
    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor;
    // std::vector<std::vector<double>> controlPoints;
    // vtkSmartPointer<vtkActor> controlPointActor;
    vtkSmartPointer<vtkPoints> controlPointData;
    vtkSmartPointer<vtkPolyData> controlPointPolyData;
    vtkSmartPointer<vtkVertexGlyphFilter> controlPointGlyphFilter;
    vtkSmartPointer<vtkPolyDataMapper> controlPointMapper;
    vtkSmartPointer<vtkActor> controlPointActor;
    vtkSmartPointer<vtkActor> bezierActor;
    std::vector<double> centroid;
    std::vector<std::vector<double>> controlPoints; // 存储控制点
    vtkSmartPointer<vtkPolyData> stlPolyData;





    vtkSmartPointer<vtkCellPicker> picker;//鼠标点击功能
    vtkSmartPointer<vtkRenderWindowInteractor> interactor;


    struct PointPairKey {
        std::vector<double> p1;
        std::vector<double> p2;

        bool operator<(const PointPairKey& other) const {
            return std::tie(p1, p2) < std::tie(other.p1, other.p2);
        }
    };
    std::map<PointPairKey, vtkSmartPointer<vtkPolyData>> pathCache;


     bool isAddControlPointEnabled=false;

    bool isTranslucentEnabled=false;

     //STL模型对象
     vtkSmartPointer<vtkActor> STLmodelActor;





};




#endif // MAINWINDOW_H
